#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main(int argc, char **argv)
{
	ostringstream sout;
	
	string n;
	cin >> n;
	while (n.length() != 1 || n[0] != '0')
	{
		while (n.length() != 1)
		{
			int sum = 0;
			for (unsigned int i = 0; i < n.length(); ++i)
			{
				sum += (n[i] - '0');
			}
			sout.str("");
			sout << sum;
			n = sout.str();
		}
		cout << n << endl;
		cin >> n;
	}
	return 0;
}
